package com.snail.readyvr.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

import com.snail.readyvr.R;
import com.snail.readyvr.application.MyApplication;
import com.snail.readyvr.rest.GetAccountInfoUtils;
import com.snail.readyvr.util.StartActivityUtils;
import com.snail.readyvr.util.Utils;

import butterknife.OnClick;


/**
 * Created by MRKING on 2016/11/23.
 */

public class SelectChannelActivity extends BaseVRImageActivity {

    private long exitTime = 0;

    @Override
    protected void hasGetAllPermissions() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(Utils.sUser != null)
            GetAccountInfoUtils.getAccountInfo(((MyApplication)getApplication()).getApplicationComponent().getLoginRestClient());
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_select_channel;
    }

    @Override
    protected void init() {
    }


    @OnClick({R.id.beauty_channel_img, R.id.other_channel_img})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.beauty_channel_img:
                StartActivityUtils.startVideoPlayActivity(this);
                //StartActivityUtils.startPersonalCenterActivity(this);
                /*Intent intent = new Intent("com.snail.readyvr.activity.UnityPlayerActivity", Uri.parse("readyvr://snail.com"));
                intent.putExtra(IntentParams.UNITY_PARAM, "{\"channelid\":\"1005\",\"host\":\"http://epg.readyvr.woniucloud.com/\",\"projectStyle\":\"3\",\"sessionid\":\"148187683741\",\"token\":\""+ Utils.token +"\",\"viewAngle\":\"88\"}");

                startActivity(intent);*/
               //finish();
                break;
            case R.id.other_channel_img:
                StartActivityUtils.startAddVideoActivity(this);
               //finish();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), getString(R.string.app_exit), Toast.LENGTH_LONG).show();
                exitTime = System.currentTimeMillis();

            } else {
                Log.d(TAG, "exit app");
                finish();
                //MobclickAgent.onKillProcess(this);
                //System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if(Utils.sUser != null)
            GetAccountInfoUtils.getAccountInfo(((MyApplication)getApplication()).getApplicationComponent().getLoginRestClient());

    }
}
